package com.fr.report.highlight;

import com.fr.base.Style;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.dialog.core.CellBorderStyle;
import com.fr.report.CellElement;
import com.fr.report.script.Calculator;
import java.awt.Color;

public class BorderHighlightAction extends AbstractHighlightAction
{
  private int topLine;
  private int bottomLine;
  private int leftLine;
  private int rightLine;
  private Color topColor;
  private Color bottomColor;
  private Color leftColor;
  private Color rightColor;

  public BorderHighlightAction()
  {
  }

  public BorderHighlightAction(CellBorderStyle paramCellBorderStyle)
  {
    if (paramCellBorderStyle == null)
      return;
    this.topLine = paramCellBorderStyle.getTopStyle();
    this.topColor = paramCellBorderStyle.getTopColor();
    this.bottomLine = paramCellBorderStyle.getBottomStyle();
    this.bottomColor = paramCellBorderStyle.getBottomColor();
    this.leftLine = paramCellBorderStyle.getLeftStyle();
    this.leftColor = paramCellBorderStyle.getLeftColor();
    this.rightLine = paramCellBorderStyle.getRightStyle();
    this.rightColor = paramCellBorderStyle.getRightColor();
  }

  public CellBorderStyle getCellBorder()
  {
    CellBorderStyle localCellBorderStyle = new CellBorderStyle();
    localCellBorderStyle.setTopStyle(getLine(this.topLine));
    localCellBorderStyle.setBottomStyle(getLine(this.bottomLine));
    localCellBorderStyle.setLeftStyle(getLine(this.leftLine));
    localCellBorderStyle.setRightStyle(getLine(this.rightLine));
    localCellBorderStyle.setTopColor(getColor(this.topColor));
    localCellBorderStyle.setBottomColor(getColor(this.bottomColor));
    localCellBorderStyle.setLeftColor(getColor(this.leftColor));
    localCellBorderStyle.setRightColor(getColor(this.rightColor));
    return localCellBorderStyle;
  }

  public void action(CellElement paramCellElement, Calculator paramCalculator)
  {
    if (paramCellElement == null)
      return;
    Style localStyle = paramCellElement.getStyle();
    paramCellElement.setStyle(localStyle.deriveBorder(getLine(this.topLine), getColor(this.topColor), getLine(this.bottomLine), getColor(this.bottomColor), getLine(this.leftLine), getColor(this.leftColor), getLine(this.rightLine), getColor(this.rightColor)));
  }

  public int getLine(int paramInt)
  {
    if (paramInt != 0)
      return paramInt;
    return 0;
  }

  public Color getColor(Color paramColor)
  {
    if (paramColor != Color.black)
      return paramColor;
    return Color.black;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if ((paramXMLableReader.isChildNode()) && ("Border".equals(paramXMLableReader.getTagName())))
    {
      this.topLine = Integer.parseInt(paramXMLableReader.getAttr("topLine"));
      this.topColor = new Color(Integer.parseInt(paramXMLableReader.getAttr("topColor")), true);
      this.bottomLine = Integer.parseInt(paramXMLableReader.getAttr("bottomLine"));
      this.bottomColor = new Color(Integer.parseInt(paramXMLableReader.getAttr("bottomColor")), true);
      this.leftLine = Integer.parseInt(paramXMLableReader.getAttr("leftLine"));
      this.leftColor = new Color(Integer.parseInt(paramXMLableReader.getAttr("leftColor")), true);
      this.rightLine = Integer.parseInt(paramXMLableReader.getAttr("rightLine"));
      this.rightColor = new Color(Integer.parseInt(paramXMLableReader.getAttr("rightColor")), true);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Border").attr("topLine", getLine(this.topLine)).attr("topColor", getColor(this.topColor).getRGB()).attr("bottomLine", getLine(this.bottomLine)).attr("bottomColor", getColor(this.bottomColor).getRGB()).attr("leftLine", getLine(this.leftLine)).attr("leftColor", getColor(this.leftColor).getRGB()).attr("rightLine", getLine(this.rightLine)).attr("rightColor", getColor(this.rightColor).getRGB()).end();
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("<Border").append(" topLine=\"").append(getLine(this.topLine)).append("\" topColor=\"").append(getColor(this.topColor).getRGB()).append("\" bottomLine=\"").append(getLine(this.bottomLine)).append("\" bottomColor=\"").append(getColor(this.bottomColor).getRGB()).append("\" leftLine=\"").append(getLine(this.leftLine)).append("\" leftColor=\"").append(getColor(this.leftColor).getRGB()).append("\" rightLine=\"").append(getLine(this.rightLine)).append("\" rightColor=\"").append(getColor(this.rightColor).getRGB()).append("\">").append("</Border>");
  }
}